<?php
	$query = "select * from `radio_dj` where `userid`='$id'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)) {
		$djprofile = mysql_fetch_array($result);
		$dj_id = $djprofile['id'];


		if ($_REQUEST['delete']){
			$exception_id = escapestr($_REQUEST['delete']);
			$query 	= "delete from `radio_exception` where `id`='$exception_id' and `dj`='$dj_id'";
			$result = mysql_query($query);
			if ($result) {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_exceptiondeleted"),GetLangString($lang,"msg_exceptiondeleted"));  
			} else {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror").$query);  
			}
		}
//--
		if ($_REQUEST['add']){
			$day 	= escapestr($_REQUEST['day']);
			$month =  escapestr($_REQUEST['month']);
			$year =  escapestr($_REQUEST['year']);
			$date = $year.$month.$day;
			
			$query 	= "insert into `radio_exception` (`dj`,`date`) values ('$dj_id','$date')";
			$result = mysql_query($query);
			if ($result) {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_exceptionadded"),GetLangString($lang,"msg_exceptionadded"));  
			} else {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror").$query);  
			}
		}

//--


		$query 	= "select * from `radio_exception` where `dj`='$dj_id' order by `date` asc";
		$result = mysql_query($query);
$txt = "<center><table border=\"1\" width=\"90%\"><tr>
			<td width=\"25%\">".GetLangString($lang,"txt_day")."</td><td width=\"25%\">".GetLangString($lang,"txt_month")."</td><td width=\"25%\">".GetLangString($lang,"txt_year")."</td><td width=\"25%\"></td></tr>";

		while ($exception = mysql_fetch_array($result)) {
			$year 	= substr($exception['date'],0,4);
			$month  =  substr($exception['date'],4,2);
			$day 		=	  substr($exception['date'],6,2);
			$ex 			= $exception[id] ;
			$delete = "<a href=\"/index.php?do=djexception&delete=$ex\">".GetLangString($lang,"txt_delete")."</a>"; 
			$txt .= "<tr><td>$day</td><td>$month</td><td>$year</td><td>$delete</td></tr>";
		}
		$txt .= "</table>";
		$SITE_MIDDLE .= FormatElement(GetLangString ($lang,"txt_exceptions"),$txt); 


		
		$frm = "<form action=\"/index.php?do=djexception\" method=\"post\"><center><table style =\"padding: 0\" border=\"0\"><tr><td width=\"33%\">".
		FormatSmallElement( GetLangString ($lang, "txt_day") , "<input value=\"".$profileinfo['day']."\" name=\"day\" maxlenght=\"2\">").
		"</td><td width=\"33%\">".
		FormatSmallElement( GetLangString ($lang, "txt_month") , "<input value=\"".$profileinfo['month']."\" name=\"month\" maxlenght=\"2\">").
		"</td><td width=\"33%\">".
		FormatSmallElement( GetLangString ($lang, "txt_year") , "<input value=\"".$profileinfo['year']."\"  name=\"year\" maxlenght=\"4\">").
		"</td></tr></table></center><input name=\"add\" value=\"".GetLangString($lang,"txt_save")."\"type=\"submit\">";

		$SITE_MIDDLE .= FormatElement(GetLangString ($lang,"txt_addexception"),$frm); 




	}else {
		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_nodjerror"));
	} 

?>
